#include "Alice/ECS/SystemMngr.h"

namespace Alice
{

void SystemMngr::Before()
{
    for (auto pair : m_type_to_system)
    {
        pair.second->Before();
    }
}

void SystemMngr::Update()
{
    // 调用所有系统的更新函数
    for (auto pair : m_type_to_system)
    {
        pair.second->OnUpdate();
    }
}

void SystemMngr::After()
{
    for (auto pair : m_type_to_system)
    {
        pair.second->After();
    }
}

void SystemMngr::UpdateEntitys(Entity entity, Signature signature)
{
    for (auto pair : m_type_to_system)
    {
        const char* type_name = pair.first;
        Signature system_signature = m_type_to_signature[ type_name ];
        if ((signature & system_signature) == system_signature)
        {
            pair.second->entitys.insert(entity);
        }
        else
        {
            pair.second->entitys.erase(entity);
        }
    }
}

} // namespace Alice
